// pages/login/index.js
import net from '../../utils/net.js'
import { inputgetName } from '../../utils/inputBothBind.js'

Page({
  data: {
    username: '18190718818',
    password: '2019rtxlk'
  },
  inputgetName: inputgetName,
  login:function() {
    if(!this.data.username || !this.data.password) {
      wx.showToast({
        title: '请填写完整',
        icon:"none"
      })
      return
    }

    net.http({
      url: '/api/index/index?method=login',
      data: {
        'tel': this.data.username,
        'password': this.data.password
      }, 
      isShowLoading: true,
      successCb: this.successCb
    })
  },
  toRegister:function() {
    wx.navigateTo({
      url: '/pages/register/index',
    })
  },
  toForgetPwd:function() {
    wx.navigateTo({
      url: '/pages/forgetPwd/index',
    })
  },
  successCb: function(res) {
    wx.showToast({
      title: res.msg,
      icon: 'success'
    })
    wx.setStorage({
      key: "xlk_token",
      data: res.data.token
    })
    wx.setStorage({
      key: "xlk_uid",
      data: res.data.id
    })
    wx.setStorage({
      key: "xlk_real_state",
      data: res.data.state
    })
    setTimeout(function() {
      wx.switchTab({
        url: '/pages/index/index',
      })
    }, 500)
  },

  onLoad: function (options) {

  },

  onReady: function () {

  },

  onShow: function () {

  },

  onHide: function () {

  },

  onUnload: function () {

  },

  onPullDownRefresh: function () {

  },

  onReachBottom: function () {

  },

  onShareAppMessage: function () {

  }
})